****** REPLICATION DATASET FOR RASMUSSEN AND KNUTSEN 2024 WORLD POLITICS ******

* STATA 18

*Programs to install*
findit estout
****** RUN ****
use "filepath here" 


*** extract information needed for TABLE 1 ***
*county share pension system
tab county old_age_number if year==1925 & old_age_number!=0
estpost tabstat old_age_number if year==1925 & old_age_number!=., by(county) stat(sum n mean)
estpost tabstat old_age_pension if year==1925 & old_age_number!=., by(county) stat(sum n)
*County support for political parties
bysort county: sum socialist_share 
bysort county: sum workerdemos_share
bysort county: sum farmers_share
bysort county: sum liberal_share
bysort county: sum conservative_share


*** TABLE 2

xtset muni year

*** Sample limit  
logit  d.old_age_pension l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period if exit!=1 ,cluster(muni)
estimates store sample1

**** col 1 in table 2
logit  d.old_age_pension l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share if _est_sample1==1 ,cluster(muni)
margins, dydx( l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share) post 
estimates store borg_baseline
**** col 2 in table 2
logit  d.old_age_pension l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period if exit!=1 ,cluster(muni) 
margins, dydx( l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period) post 
estimates store borg_fe 
*** col 3 in table 2
logit  d.old_age_pension l.local_share  l.workerdemos_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar i.county i.election_period popdens turnout utgifter_totalt  occupindupct occupservicepct occupseapct if exit!=1 ,cluster(muni)
margins, dydx( l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period) post 
estimates store controls_borg_intro
**** col 4 in table 2
reg  d.old_age_number  l.local_share l.temperance_share  l.workerdemos_share l.farmers_share l.liberal_share l.conservative_share    if _est_borg_baseline==1,cluster(muni)
margins, dydx(l.local_share l.temperance_share  l.workerdemos_share l.farmers_share l.liberal_share l.conservative_share ) post 
estimates store baseline_number
**** col 5 in table 2
reg  d.old_age_number  l.local_share l.temperance_share  l.workerdemos_share l.farmers_share l.liberal_share l.conservative_share i.county i.election_period  if _est_borg_baseline==1,cluster(muni)
margins, dydx(l.local_share l.temperance_share  l.workerdemos_share l.farmers_share l.liberal_share l.conservative_share i.county i.election_period) post 
estimates store fe_number
**** col 6 in table 2
reg  d.old_age_number  l.local_share l.temperance_share   l.workerdemos_share l.farmers_share l.liberal_share l.conservative_share i.county i.election_period popdens turnout utgifter_totalt  occupindupct occupservicepct occupseapct if _est_controls_borg_intro==1,cluster(muni)
margins, dydx(l.local_share l.temperance_share   l.workerdemos_share l.farmers_share l.liberal_share l.conservative_share  popdens turnout utgifter_totalt  occupindupct occupservicepct occupseapct i.county i.election_period) post 
estimates store controls_number
* create table 2
  esttab borg_baseline borg_fe controls_borg_intro  baseline_number fe_number controls_number using "municipality_table1.rtf", r2 label nonotes  nomtitles   title("Table XX Average marginal effects models on introduction of old-age pension (models 1-2, logistic regression), and number of programs introduced (models 3-4, OLS) ") b(a2) replace ///
                                  indicate("County dummies=*county*" "Election dummies =*election_period*" "Controls =*popdens turnout utgifter_totalt  occupindupct occupservicepct occupseapct")  ///
	                                addnotes(t statistics in parentheses. County and election dummies excluded for presentational reasons. Controls included in models 2 and 4 are, population density, turnout, poor relief expenditures, workers engaged in industry in percent of labor force and the same for services, and seafaring as explained in the text. For models 1-2 estimated with logistic regression, the dependent variable takes the value 1 if a municipality introduced a pension in that year and 0 if not. For models 3-4 estimated with OLS, the dependent variable takes a value between 1 and 3 if in a given year the municipality introduced that specific number of pensions and 0 at all other times. Once a municipality has introduced a pension system it is excluded from the sample in all models. All election variables are lagged one year, since they would only be able to influence policy the following year. Logistic regression drops all observations perfectly predicted. )

*** APPENDIX Tables

*descriptive statistics Appendix A3
estpost  sum  old_age_pension old_age_number socialist_share local_share  workerdemos_share temperance_share farmers_share liberal_share conservative_shar popdens turnout utgifter_totalt  occupindupct occupservicepct occupseapct if _est_sample1==1
esttab  using "descrptives_muni.rtf", replace cells("mean sd min max") nomtitle nonumber

*correlate statistics Appendix A4
 estpost correlate  old_age_pension old_age_number socialist_share local_share  workerdemos_share temperance_share farmers_share liberal_share conservative_shar popdens turnout utgifter_totalt  occupindupct occupservicepct occupseapct if _est_sample1==1, matrix listwise
esttab  using "pwcorr.rtf", replace unstack not noobs compress 


**** Figures 


**** Figure 1 ****
logit  d.old_age_pension l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period if exit!=1 ,cluster(muni)
margins, at(l.farmers_share=(0(0.20)1))
marginsplot, saving(farmerslocal, replace) title("") xtitle("Farmers Share")  ytitle("Prob. introducing pension")
margins, at(l.liberal_share=(0(0.20)1))
marginsplot, saving(liberal_share, replace) title("") xtitle("Liberal Share")  ytitle("")
margins, at(l.conservative_shar=(0(0.20)1))
marginsplot, saving(conservative_shar, replace) title("") xtitle("Conservative Share")  ytitle("Prob. introducing pension")
margins, at(l.local_share=(0(0.20)1))
marginsplot, saving(local_share, replace) title("") xtitle("Non-programmatic share")  ytitle("")
margins, dydx( l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period) post 
graph combine farmerslocal.gph liberal_share.gph conservative_shar.gph local_share.gph, col(2) ycommon  
**** Figure 2 ****
logit  d.old_age_pension  l.socialist_share l.workerdemos_share i.county i.election_period if exit!=1 ,cluster(muni)
estimates store figure_xx
margins, at(l.socialist_share=(0(0.20)1))
marginsplot, saving(localsocialists, replace) title("") xtitle("Socialist share") ytitle("Prob. introducing pension")
margins, at(l.workerdemos_share=(0(0.20)1))
marginsplot, saving(workerdemos_share, replace) title("") xtitle("Social Liberal share") ytitle("Prob. introducing pension") ylabel(0 (.1) .5)


*** Appendix Figures ****

**** Appendix A5
logit  d.old_age_pension l.local_share l.temperance_share l.farmers_share l.liberal_share l.conservative_shar l.workerdemos_share i.county i.election_period if exit!=1 ,cluster(muni)
estimates store figure_xx
margins, at(l.farmers_share=(0(0.20)1))
marginsplot, saving(farmerslocal, replace) title("") xtitle("")  ytitle("Prob. introducing pension")
histogram farmers_share  if _est_figure_xx==1, percent saving(localhistogramfarm, replace) xtitle("Farmers share")
margins, at(l.liberal_share=(0(0.20)1))
marginsplot, saving(liberal_share, replace) title("") xtitle("")  ytitle("")
histogram liberal_share  if _est_figure_xx==1, percent saving(localhistogramlib, replace) xtitle("Liberal share")
margins, at(l.conservative_shar=(0(0.20)1))
marginsplot, saving(conservative_shar, replace) title("") xtitle("")  ytitle("Prob. introducing pension")
histogram conservative_shar  if _est_figure_xx==1 & conservative_shar<1.01, percent saving(localhistogramcons, replace) xtitle("Conservative share")
margins, at(l.local_share=(0(0.20)1))
marginsplot, saving(local_share, replace) title("") xtitle("")  ytitle("")
histogram local_share  if _est_figure_xx==1 & local_share<1.01, percent saving(localhistogramlocal, replace) xtitle("Non-programmatic share")
graph combine farmerslocal.gph localhistogramfarm.gph, col(1)  
graph combine liberal_share.gph localhistogramlib.gph, col(1)  
graph combine conservative_shar.gph localhistogramcons.gph, col(1)  
graph combine local_share.gph localhistogramlocal.gph, col(1)  

**** Appendix A6 
logit  d.old_age_pension l.local_share l.socialist_share  i.county i.election_period if exit!=1 & local_share<1.1 ,cluster(muni)
margins, at(l.local_share=(0(0.20)1))
marginsplot, saving(local_share, replace) title("") xtitle("")  ytitle("Prob. introducing pension")
histogram local_share  if _est_figure_xx==1 & local_share<1.1, percent saving(localhistogram, replace) xtitle("Non-programmatic share")
graph combine local_share.gph localhistogram.gph, col(1) xcommon


